package com.example.store2.Controller;

import com.example.store2.Service.AttentionService;
import com.example.store2.pojo.Atten;
import com.example.store2.pojo.Attention;
import com.example.store2.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/attention")
@Slf4j
public class AttentionController {
    @Autowired
    private AttentionService attentionService;

    /**
     * 显示关注列表的资源信息
     * @param id
     * @param classesId
     * @param resourcesName
     * @return
     */
    @GetMapping
    public Result list(Integer id,Integer classesId,String resourcesName){
        log.info("id:{},classId:{},resourcesName:{}",id,classesId,resourcesName);
        List<Attention>attentionList= attentionService.list(id,classesId,resourcesName);//利用当前用户id查询所有关注人的所有资源
        return Result.success(attentionList);
    }

    /**
     *  添加关注资源
     * @param atten
     * @return
     */
   @PostMapping
    public Result add(@RequestBody Atten atten){
        log.info("添加的对象为{}",atten);
        if(attentionService.add(atten))
            return Result.success();
        else
            return Result.error("该资源已被添加");
    }
}
